<?php
	$log_str = "mysql日志(大于1M自动清空)";
	$filename = "E:/htdocs/mysql.log";
	$url = $_SERVER['PHP_SELF'];

	// 删除日志文件
	if( isset($_GET['act']) && $_GET['act'] == 'del' ) {
		@unlink("$filename");
		header("Location:".$url);
	}

	//不存在该文件则新建
	if( !file_exists($filename) ) {
		file_put_contents($filename, $log_str."\r\n",FILE_APPEND);
		if ( !is_writable($filename) ){
			die("log文件:" .$filename. "不可写，请检查！ 或尝试删除log文件 ！");
		}
		
	}
	//如果日志文件大于1M，则清空
	if( abs(filesize($filename) > (1024*1024*1)) ) {
		 file_put_contents($filename, $log_str);
	}
	$str = file_get_contents($filename);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="php工具箱" />
<meta name="description" content="php工具箱" />
<title>php工具箱</title>
<script src="http://cdn.staticfile.org/jquery/2.1.1-rc2/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/ace/1.1.3/ace.js"></script>
<script>
$(function(){
    //实例化代码编辑器
    editor = ace.edit("editor");
    document.getElementById('editor').style.fontSize='14px';
    //设置编辑器的语法和高亮
    editor.setTheme("ace/theme/monokai");
    editor.getSession().setMode("ace/mode/mysql");
    //设置编辑器自动换行
    editor.getSession().setWrapLimitRange(null, null);
    editor.getSession().setUseWrapMode(true);
    //不显示垂直衬线
    editor.renderer.setShowPrintMargin(false);
    editor.setReadOnly(true); //设置编辑器为只读
    //editor.gotoLine(2); //跳转到指定行
    //使编辑器获得输入焦点
    //editor.focus();
})
</script>

<style>
	body { background:#272822 }
	a { text-decoration:none }
	p {margin: 0;}
	#editor { margin: 0; position: absolute; top: 7%; bottom: 0; left: 0; right: 0; }
	.success { background:#00B2EE; border:1px solid; border-color:#009ACD; padding:5px 5px 5px 5px; border-radius: 15px; }
	.time { border:0px solid; border-radius: 8px; border-color:#a2d246; padding:8px; width:170px; color:#eee; }
	
</style>
</head>
<body>
	<div class='contents' style="padding:10px;font-size:16px;">
		<font style="color:#FF6600;font-size:19px;">sql调试工具、追踪 </font>
		<a href="?act=del" class="success">清空log日志</a>
		<a href="?act=freshen<?php echo time();?>#end" class="success">刷新页面</a>
		<span>文件总大小：<?php echo filesize($filename)/1024;?>kb</span>
		<div id="editor"><?php echo $str;?></div>
		<br>
	</div>
</body>
</html>